package com.yhy.wxzn.wcs.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;


public enum PlcTaskProgress {
    /**
     * 等待入库任务分配设备
     */
    WAIT(0, "等待"),

    /**
     * 所有设备任务完成(仅指设备，除小车)
     */
    ALL_DEVICE_COMPLETE(-100, "所有设备完成");
    @EnumValue
    private int taskProgress;
    @JsonValue
    private String description;

    PlcTaskProgress(int taskProgress, String description) {
        this.taskProgress = taskProgress;
        this.description = description;
    }

    @Override
    public String toString() {
        return description;
    }

    public static PlcTaskProgress parseTaskProgress(int taskProgress) {
        PlcTaskProgress[] taskProgresses = PlcTaskProgress.values();
        for (PlcTaskProgress progress : taskProgresses) {
            if (progress.taskProgress == taskProgress) {
                return progress;
            }
        }
        throw new IllegalArgumentException("任务进度参数异常");
    }

    public static PlcTaskProgress getByTaskProgress(int taskProgress) {
        PlcTaskProgress[] taskProgresses = PlcTaskProgress.values();
        for (PlcTaskProgress progress : taskProgresses) {
            if (progress.taskProgress == taskProgress) {
                return progress;
            }
        }
        throw new IllegalArgumentException("任务进度参数异常");
    }


    public static PlcTaskProgress parseTaskProgress(String description) {
        PlcTaskProgress[] taskProgresses = PlcTaskProgress.values();
        for (PlcTaskProgress progress : taskProgresses) {
            if (progress.description.equals(description)) {
                return progress;
            }
        }
        throw new IllegalArgumentException("任务进度参数异常");
    }


    public String getDescription() {
        return description;
    }

    public int getTaskProgress() {
        return taskProgress;
    }
}
